/*
 * @Author: guoyangf
 * @Date: 2020-05-28 11:04:46
 * @LastEditTime: 2020-07-27 09:54:39
 * @Description: file content
 */
import React, { Component } from 'react';
import { createPage, getMultiLang } from 'nc-lightapp-front'

export default function createJobPage(opt) {
    let sscMultiLangConfig = opt.sscMultiLangConfig || {};
    let defaultMultiModule = ['job'];
    if (sscMultiLangConfig['ssctp']) {
        defaultMultiModule = defaultMultiModule.concat(sscMultiLangConfig['ssctp'])
    }
    sscMultiLangConfig['ssctp'] = defaultMultiModule;

    return (App) => {

        class JobAppWraper extends Component {
            constructor(props) {
                super();
                this.state = {
                    sscMultiLang: {}
                }
                this.sscAppType = opt.sscAppType;
                this.sscJobConfig = opt.sscJobConfig || {};
                this.sscMultiLangPromise = new Promise((resolve, reject) => {
                    getMultiLang({
                        moduleId: sscMultiLangConfig,
                        callback: (multiLang) => {
                            resolve(multiLang);
                        }
                    })
                })
                this.sscMultiLangPromise.then((sscMultiLang) => {
                    setTimeout(() => { //平台getMultiLang有http缓存。所以用setTimeout，防止无效setState
                        this.setState({
                            sscMultiLang
                        })
                    })
                })

                window.__SSC_NCProps = props;
                window.__SSC_MultiLangPromise = this.sscMultiLangPromise;

            }

            render() {
                return <App sscAppType={this.sscAppType} sscJobConfig={this.sscJobConfig} {...this.props} sscMultiLang={this.state.sscMultiLang} sscMultiLangPromise={this.sscMultiLangPromise} />
            }
        }

        return createPage(opt)(JobAppWraper)
    }
}